package com.qifenqian.turbot.util

import android.app.Activity

/**
 * @author H
 * @createDate 2018/6/16 15:45
 * @reference
 * @updateDate
 * @description Activity收集器
 * @detail
 * @since
 */
object ActivityCollector {

    private var map = mapOf<String, ArrayList<Activity>>()
    private var activities: ArrayList<Activity> = arrayListOf()
    fun addActivity(activity: Activity, tag: String) {
        activities.add(activity)
        map = mapOf(tag to activities)
        if (!map[tag]!!.contains(activity)) {
            map[tag]!!.add(activity)
        }
        Lcat.d("addActivity", map)
    }

    fun removeActivity(activity: Activity, tag: String) {
        if (!map.isEmpty() && map[tag]!!.contains(activity)) {
            map[tag]!!.remove(activity)
        }
        Lcat.d("removeActivity", map)
    }

    fun finishAll(tag: String) {
        if (!map.isEmpty() && !map[tag].isNullOrEmpty()) {
            for (activity in map[tag]!!) {
                if (!activity.isFinishing) {
                    activity.finish()
                }
            }
        }
        Lcat.d("finishAll", map)
    }
}
